from django.db import models

"""
家电分类:
    冰箱：
        酒柜:
            不锈钢酒柜:
                钛合金
                铝合金   
            玻璃酒柜  
        多门   
        三门  
        双门
    洗衣机：
        烘干机  
        高科技洗衣机
    电饭煲

"""


class Category(models.Model):
    """
    id，分类名，上级分类，级别
    """

    name = models.CharField('分类名', max_length=20)
    parent = models.ForeignKey("self", on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "category_table"


class Tag(models.Model):
    name = models.CharField('标签名', max_length=20)
    cate = models.ForeignKey(Category, on_delete=models.CASCADE,null=True)

    class Meta:
        db_table = "tag_table"


class Goods(models.Model):
    """
    商品名    分类  标签  价格  库存  销量 图片 详情 规格包装 售后服务 商品评论数
    """
    name = models.CharField(max_length=20)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    tag = models.ForeignKey(Tag, on_delete=models.CASCADE)
    pic = models.ImageField(upload_to="media/pic",default="static/admin/images/default.jpg")
    pic1 = models.CharField("七牛云图片地址",max_length=200,default="")
    price = models.IntegerField('价格')
    store = models.IntegerField('库存')
    sale = models.IntegerField('销量',default=0)
    content = models.TextField('详情')
    baozhuang = models.TextField('包装')
    fuwu = models.TextField('售后服务')
    comment_count = models.IntegerField('商品评论数', default=0)

    class Meta:
        db_table = "goods_table"


class Goods_Item(models.Model):
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE)
    name = models.CharField('属性名', max_length=20)
    value = models.CharField('属性值', max_length=120)

    class Meta:
        db_table = "goods_item_table"

